<?php
if (isset ( $vars ['assignment_guid'] )) {
	$assignment = get_entity($vars['assignment_guid']);
}

if($assignment){
	$title = $assignment->title;
	$description = $assignment->description;
	$deadline = $assignment->deadline;
	
}

$assignto_label = elgg_echo ( 'submana:assignment:assignto' );
$project = get_entity($vars ['project_guid']);
// assign to
$metadata_options = array (
		array (
				'name' => 'group_project',
				'value' => $project->group_project
		),
		array (
				'name' => 'semester',
				'value' => $project->semester
		),
		array (
				'name' => 'academic_year',
				'value' => $project->academic_year
		)
);

$options = array (
		'type' => "object",
		'subtype' => 'project',
		'deadline_edited' => $ar_deadline_editted [$index],
		'container_guid' => $vars ['group_guid'],
		'metadata_name_value_pairs' => $metadata_options
);

$projects = elgg_get_entities_from_metadata ( $options );


// initializing assignto options
$options = array (
		"$project->group_project`$project->semester`$project->academic_year" => elgg_echo ( 'submana:assignment:assignto:all' ) 
);
foreach ( $projects as $project ) {
	if($project)
	$options [$project->guid] = $project->title;
}

if (isset ( $vars ["project_guid"] )) {
	$assignto_value = $vars ['project_guid'];
} else if($assignment) {
	$assignto_value = $assignment->container_guid;
} else {
	$assignto_value = 0; 
}
$assignto_input = elgg_view ( 'input/dropdown', array (
		'name' => 'assignto',
		'value' => $assignto_value,
		'options_values' => $options 
) );

// title
$title_label = elgg_echo ( 'title' );
$title_input = elgg_view ( 'input/text', array (
		'name' => "title",
		'value' => $title 
) );

// description
$description_lable = elgg_echo ( 'description' );
$description_input = elgg_view ( 'input/longtext', array (
		'name' => "description",
		'value' => $description 
) );

// deadline
$deadline_label = elgg_echo ( 'Hạn nộp' );
$deadline_input = elgg_view ( 'input/date', array (
		'name' => 'deadline',
		'value' => $deadline 
) );

// group_guid
$group_guid = elgg_view ( 'input/hidden', array (
		'name' => "group_guid",
		'value' => $vars ['group_guid'] 
) );

$assignment_guid = elgg_view ( 'input/hidden', array (
		'name' => "assignment_guid",
		'value' => $assignment->guid,
) );

// buttons
$save_button = elgg_view ( 'input/submit', array (
		'value' => elgg_echo ( 'submana:addprojects:save' ) 
) );
$reset_button = elgg_view ( 'input/reset', array (
		'value' => elgg_echo ( 'submana:addprojects:reset' ) 
) );

echo <<<___HTML
<div>
	<label>$title_label</label>
	$title_input
</div>
<div>
	<label>$description_lable</label>
	$description_input
</div>

<div style="width:40%;">
	<label>$deadline_label</label>
	$deadline_input
</div>

<div style="width:40%;">
	<label>$assignto_label</label>
	$assignto_input
</div>
<div>
	$group_guid
	$assignment_guid
	$save_button
	$reset_button
</div>
___HTML;

?>